user, please set ${}", username_var)))
}
};
- let email = git_config.and_then(|g| g.get_string("user.email").ok());
+ let email = git_config.and_then(|g| g.get_string("user.email").ok())
+ .or_else(|| env::var("EMAIL").ok());
let name = name.trim().to_string();
let email = email.map(|s| s.trim().to_string());
[cargo-new]
# This is your name/email to place in the `authors` section of a new Cargo.toml
# that is generated. If not present, then `git` will be probed, and if that is
-# not present then `$USER` will be used (with no email).
+# not present then `$USER` and `$EMAIL` will be used.
name = "..."
email = "..."
assert!(contents.contains(r#"authors = ["foo"]"#));
});
+test!(finds_author_email {
+ // Use a temp dir to make sure we don't pick up .cargo/config somewhere in
+ // the hierarchy
+ let td = TempDir::new("cargo").unwrap();
+ assert_that(cargo_process("new").arg("foo")
+ .env("USER", "bar")
+ .env("EMAIL", "baz")
+ .cwd(td.path().clone()),
+ execs().with_status(0));
+
+ let toml = td.path().join("foo/Cargo.toml");
+ let mut contents = String::new();
+ File::open(&toml).unwrap().read_to_string(&mut contents).unwrap();
+ assert!(contents.contains(r#"authors = ["bar <baz>"]"#));
+});
+
test!(finds_author_git {
my_process("git").args(&["config", "--global", "user.name", "bar"])
.exec().unwrap();